package com.kiln.juxingqs.ui.vm

import android.app.Application
import androidx.lifecycle.MutableLiveData
import client.global.commlib.network.data.JsonResult
import client.global.commlib.network.data.Ret
import com.kiln.juxingqs.api.bean.ZrOrder
import com.kiln.juxingqs.ui.viewmodel.MiddleVm

class ZrPickOrderViewModel(app: Application) : MiddleVm(app) {
    val isShowing = MutableLiveData<Boolean>(false)

    val isOneLoading = MutableLiveData<Boolean>(false)
    val pageOne = MutableLiveData<Int>(0)
    val callOne = MutableLiveData<JsonResult<ZrOrder>>()
    val callSpecialPrices = MutableLiveData<JsonResult<ZrOrder>>()

    val zhaiPaiRet = MutableLiveData<JsonResult<Ret>>()
    val cancelRet = MutableLiveData<JsonResult<Ret>>()

//    var goods_name = MutableLiveData<String>("")
//    var deal_num = MutableLiveData<String>("")

    fun holdCall(goods_id: String?) {
        if (isOneLoading.value!!)
            return
        hold({
            server.hanging_order_hall(goods_id!!, pageOne.value!!)
        }, {
            isOneLoading.value = true
            pageOne.value = pageOne.value!! + 1
        }, {
            callOne.value = it
        }, complete = {
            isOneLoading.value = false
        })

    }

    fun holdSpecialPrice(goods_id: String?, status: String?) {
        if (isOneLoading.value!!)
            return
        hold({
            server.mall_coupon_record(goods_id!!, status!!, pageOne.value!!)
        }, {
            isOneLoading.value = true
            pageOne.value = pageOne.value!! + 1
        }, {
            callSpecialPrices.value = it
        }, complete = {
            isOneLoading.value = false
        })

    }

    fun holdZhaiPai(order_id: String?, num: String?) {
        if (isOneLoading.value!!)
            return
        hold({
            server.pick_order(order_id!!, num!!)
        }, {
            isOneLoading.value = true
            pageOne.value = pageOne.value!! + 1
        }, {
            zhaiPaiRet.value = it
        }, complete = {
            isOneLoading.value = false
        })
    }

    fun holdCancel(order_id: String) {
        if (isOneLoading.value!!)
            return
        hold({
            server.revoke_hang_order(order_id)
        }, {
            isOneLoading.value = true
            pageOne.value = pageOne.value!! + 1
        }, {
            cancelRet.value = it
        }, complete = {
            isOneLoading.value = false
        })
    }


}